import { defineStore } from 'pinia'
import { useBasicStore } from '@/store/basic'
export const useProjectInfoStore = defineStore('projectInfo', {
  state: () => {
    return {
      projectInfo: {} as any
    }
  },
  persist: {
    storage: sessionStorage,
    paths: ['projectInfo']
  },
  actions: {
    // 设置项目信息 路由跳转，项目点击 两种情况
    setProjectInfo(data: any) {
      return new Promise((resolve, reject) => {
        const { userInfo, refreshToken, token } = useBasicStore()
        const { appId, userId, username } = userInfo
        this.projectInfo = data
        window.name = JSON.stringify({
          appId,
          userId,
          userName: username,
          refreshToken,
          token,
          projectInfo: false // 清空 请求项目信息。页面刷新时，不再请求项目信息
        })
        resolve(true)
      })
    },
    // 获取项目信息
    clearProjectInfo() {
      this.projectInfo = {}
    }
  }
})
